package com.zt.english.fragment

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.Switch
import androidx.appcompat.app.AppCompatDelegate
import com.zt.english.R
import com.zt.english.activity.*
import com.zt.english.activity.audio.AudioPlayActivity
import com.zt.english.activity.video.VideoPlayActivity
import com.zt.mvvm.common.utils.gotoActivity
import com.zt.mvvm.view.BaseFragmentA

class HomeFragment : BaseFragmentA(){

    override fun setLayoutResId(): Int = R.layout.fragment_home

    @SuppressLint("UseSwitchCompatOrMaterialCode")
    override fun initView(rootView: View?, savedInstanceState: Bundle?) {
        /**
         * 模式切换
         */
        val switch = rootView?.findViewById<Switch>(R.id.id_switch)
        switch?.setOnClickListener {
            if (switch.isChecked) {
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
            }else{
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
            }
        }
        /**
         * 麦田守望者-(音频字幕联动)
         */
        rootView?.findViewById<Button>(R.id.button1)?.setOnClickListener {
            gotoActivity<AudioPlayActivity>(mContext){
                //音频播放地址
                putExtra("url","https://bmob-cdn-24469.bmobcloud.com/2020/12/08/df2869ce402734db805e97fb313ce36a.mp3")
                //assets文件夹下srt字幕文件
                putExtra("srt","麦田守望者.srt")
            }
        }
        /**
         * 青春-(音频字幕联动)
         */
        rootView?.findViewById<Button>(R.id.tlkt_btn)?.setOnClickListener {
            gotoActivity<AudioPlayActivity>(mContext){
                //音频播放地址
                putExtra("url","http://down010702.tingclass.com/lesson/shi0529/0001/1613/01-youth.mp3")
                //assets文件夹下srt字幕文件
                putExtra("srt","青春.srt")
            }
        }
        /**
         * 演讲视频-(视频字幕联动)
         */
        rootView?.findViewById<Button>(R.id.id_video)?.setOnClickListener {
            gotoActivity<VideoPlayActivity>(mContext)
        }
        /**
         * 有道翻译api使用示列
         */
        rootView?.findViewById<Button>(R.id.button2)?.setOnClickListener {
            gotoActivity<TranslateActivity>(mContext)
        }

        /**
         * TTS(Android原生api实现文本转语音)
         */
        rootView?.findViewById<Button>(R.id.tts_btn)?.setOnClickListener {
            gotoActivity<TtsDemoActivity>(mContext)
        }
    }
}